import { View, Text } from '@tarojs/components'
import Taro, { useLoad,useLaunch ,useDidShow} from '@tarojs/taro'
import './index.scss'
import { useState } from 'react'
import { AtForm, AtInput, AtButton ,AtAvatar,AtList, AtListItem} from 'taro-ui'
import request  from '../../utils/request'
export default function Index () {
  const [islogin,setislogin] = useState(false);
  const [userInfo,setUserInfo] = useState({nickname:''});
  const [count,setCount] = useState(0);
  useDidShow(() => {
    console.log('Page loaded.');
    getUserInfo();
  })
    const getdetailByStudentId = (id)=>{
    //admin/login
    request.get('/wx-course-manage-server/u/student/course/record/detailByStudentId?studentId='+id).then((res)=>{
      console.log(res);
      setCount(res||0);
    })
  }
   const getUserInfo = ()=>{
    //admin/login
    request.get('app/get-login-user-info').then((res)=>{
      console.log(res);
      setUserInfo(res);
      setislogin(true);
      Taro.setStorage({
          key:"userInfo",
          data:res
      })
      window.localStorage.setItem('userInfo',res)
      getdetailByStudentId(res.id);
    })
  }
  return (
    <div className='mypage'>
      
      <div class='userInfo'>
        <div className='tx'>
        </div>
        {
          islogin?<div className='nickname'>{userInfo?.nickname}</div>:<div onClick={()=>Taro.navigateTo({url:'/pages/login/index'})} className='nickname'>登录</div>
        }

       
      </div>
       <div className='vip-card'>会员卡
          <div className='count'>{count}次</div>
        </div>
      <div className='applist'>
        <div className='item' onClick={()=>Taro.navigateTo({url:'/pages/yylist/index'})}>预约列表</div>
      </div>
    </div>
  )
}
